define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mental/extension/index' + location.search,
                    add_url: 'mental/extension/add',
                    edit_url: 'mental/extension/edit',
                    del_url: 'mental/extension/del',
                    multi_url: 'mental/extension/multi',
                    import_url: 'mental/extension/import',
                    table: 'mental_extension',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                search:false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                
                
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user.money', title: __('User.money'), operate: 'LIKE'},
                        // {field: 'order_price', title: __('Order_price'), operate: 'LIKE'},
                        // {field: 'koudan_price', title: __('总金额'), operate: 'LIKE'},
                        
                        {field: 'total_commission', title: __('佣金总额'), operate: false},
                        {field: 'total_order', title: __('订单总额'), operate: false},
                        {field: 'total_deduction', title: __('扣除总额'), operate: false},
                        
                        // {field: 'testmain.title', title: __('Testmain.title'), operate: 'LIKE'},
                        
                        // {field: 'url', title: __('Url'), operate: false, formatter: Table.api.formatter.url},
                        // {field: 'qrcode', title: __('Image'), operate: false, formatter: function(value,row,index){
                        //     return '<a href="'+value+'" download="" style="text-decoration:none;color:#333;"><img src="'+value+'" alt="" style="width:35px;height:35px;"/><span style="font-size:8px;">点击下载</span></a>';
                        // }},
                        
                        // {field: 'qrcode', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {
                            field: 'channel_type',
                            title: __('Channel_type'),
                            searchList: {
                                "1":__('Channel_type 1'),
                                "2":__('Channel_type 2'),
                                "3":__('Channel_type 3'),
                                "4":__('Channel_type 4'),
                                "5":__('Channel_type 5'),
                                "6":__('Channel_type 6'),
                                "7":__('Channel_type 7'),
                                "8":__('Channel_type 8'),
                                "9":__('Channel_type 9'),
                                "10":__('Channel_type 10'),
                                "11":__('Channel_type 11'),
                                
                                "12":__('Channel_type 12'),
                                "13":__('Channel_type 13'),
                                "14":__('Channel_type 14'),
                                "15":__('Channel_type 15'),
                                "16":__('Channel_type 16'),
                                "17":__('Channel_type 17'),
                                "18":__('Channel_type 18'),
                                "19":__('Channel_type 19'),
                                
                                "20":__('Channel_type 20'),
                                "21":__('Channel_type 21'),
                                "22":__('Channel_type 23'),
                                "23":__('Channel_type 23'),
                                "24":__('Channel_type 24'),
                                "25":__('Channel_type 25'),
                                "26":__('Channel_type 26'),
                                "27":__('Channel_type 27'),
                                "28":__('Channel_type 28'),
                                "29":__('Channel_type 29'),
                            },
                                formatter: Table.api.formatter.normal},
                        // {field: 'status', title: __('Status'),operate: false, searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons:[
                                {
                                    name: 'order',
                                    title: '查看订单',
                                    text: '查看订单',
                                    extend: `data-area='["1100px","600px"]'`,
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa',
                                    url: 'mental/order/index',
                                    hidden: function (row) {
                                       
                                        return false;
                                    }
                                },
                                {
                                    name: 'log',
                                    title: '扣单记录',
                                    text: '扣单记录',
                                    extend: `data-area='["100%","100%"]'`,
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa',
                                    url: 'koudan/log/index/uid/{user_id}',
                                    hidden: function (row) {
                                       
                                        return false;
                                    }
                                },
                                
                                {
                                    name: 'koudan',
                                    title: '扣单规则设置',
                                    text: '扣单规则设置',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa',
                                    url: 'mental/extension/koudan',
                                    hidden: function (row) {
                                       
                                        return false;
                                    }
                                },
                                
                                ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                            
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            
            // 启动和暂停按钮
            $(document).on("click", ".btn-daochu", function () {

                var ids = Table.api.selectedids(table);
                var url = 'extension/daochu?ids='+ids;
                
                window.open(url)
                
                
                
            });
            
            
        },
        add: function () {
            Controller.api.bindevent();
        },
        koudan: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
